PASSWORD:=test
debugging:=true
debugging:=false
app:=zhenbang
AS:= test.as
CERT:=my.p12

ifneq ($(OS),Windows_NT)
OS:=$(shell uname)
NOT_LINUX=false
else
HOME:=D:
NOT_LINUX=true
BUNDLE:=../../zhenbang_bundle/
endif

ifeq ($(debugging),false)
PUBLISH:=false
else
PUBLISH:=true
endif

ASSET:=-C ../../bin/ asset config.json zhenbang.swf
ifeq ($(OS),Linux)
FLEX_HOME:=$(HOME)/flex_sdk_4.5
APP_XML:= ../../application.xml
else
FLEX_HOME:=$(HOME)/air29
APP_XML:=../../application.xml
endif
ADL:= $(FLEX_HOME)/bin/adl
ADT:=$(FLEX_HOME)/bin/adt
AMXMLC:= $(FLEX_HOME)/bin/amxmlc
SWC:=../jpeg.swc
SWF:=../../bin/$(app).swf
RM:=rm -rf
FLAGS:= -define=CONFIG::NOT_LINUX,$(NOT_LINUX) -define=CONFIG::debugging,$(debugging)

all: $(SWF)
	$(ADL) $(APP_XML) ../../bin/

$(SWF): *.as
	$(AMXMLC)  -strict=true -tools-locale en_US -omit-trace-statements=$(PUBLISH) -verbose-stacktraces=$(PUBLISH) $(AS) $(FLAGS) -source-path=.. -debug=$(debugging) -output $(SWF) -library-path+=$(SWC)

exe: $(SWF) $(CERT)
	$(ADT)  -package -storetype pkcs12 -keystore $(CERT) -storepass $(PASSWORD) -target bundle $(BUNDLE) $(APP_XML) $(ASSET) 

zip:
	cp $(SWF) $(BUNDLE)
	cd ../../ ; zip zhenbang`date -I`.zip -r zhenbang_bundle

$(CERT):
	$(ADT) -certificate -cn db0@qq.com -ou db0@qq.com -o db0@qq.com -c CN -validityPeriod 1 2048-RSA $(CERT) $(PASSWORD)

.PHONY : clean
clean:
	$(RM) $(SWF) app/* data/image data/advices ../bin/date
